<template>

    <div id="risk-huizong" class="w-h-100 pos-r flex-1 apply-container page-public-s" style="box-sizing: border-box;overflow:hidden;">
        <div class="w-h-100 ver-flex pos-a" style="box-sizing: border-box; padding: 6px;">
            <div style="box-sizing: border-box;">
                <el-card shadow="never" :body-style="{ paddingBottom: '0' }">
                    <el-form class="box-f" ref="queryForm" :inline="true">
                        <el-form-item :label="$t('b0t63v7bGsmbXkQdwW4Q0')">
                            <el-select 
                                v-model="searchVal" 
                                filterable 
                                class="m-2" 
                                :placeholder="$t('g6AmUBb2H8qwj8DuC0TH')" 
                                @change="searchChange"
                            >
                                <el-option
                                    v-for="item in searchOptions"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                />
                            </el-select>
                        </el-form-item>
                        <el-form-item>
                            <!-- 模糊查询 -->
                            <template v-if="searchVal === '1'">
                                <el-input v-model="transferVal" :placeholder="$t('yeyw245R7a6VYy19Otp1n')" />
                            </template>
                            <!-- 是否启用 -->
                            <template v-else-if="searchVal === '2'">
                                <el-select 
                                    v-model="transferVal" 
                                    filterable 
                                    class="m-2" 
                                    :placeholder="$t('4qSllUxIkPaA8Rqf3Jg8y')" 
                                    @change="acquireChange"
                                    value-key="id"
                                >
                                    <el-option
                                        v-for="item in responsiblePle"
                                        :key="item.value"
                                        :label="item.label"
                                        :value="item.value"
                                    />
                                </el-select>
                            </template>
                            <!-- 时间段查询 -->
                            <template v-else>
                                <el-date-picker
                                    v-model="transferVal"
                                    type="datetimerange"
                                    range-separator="-"
                                    :start-placeholder="$t('zxGaloajaAo1yMttcStime')"
                                    :end-placeholder="$t('zxGaloajaAo1yMttcEtime')"
                                    value-format="YYYY-MM-DD HH:mm:ss"
                                />
                            </template>
                        </el-form-item>
                        <el-form-item >
                            <el-button @click='searchClick' type="primary" icon="ele-Search"> {{ $t('a4Uw6qeAZpctNhl3u7Uge') }} </el-button>
                            <el-button @click="resetClick" icon="ele-Refresh"> {{ $t('rxCkXeM2sO75ltcf8JyVj') }} </el-button>
                        </el-form-item>
                    </el-form>
                </el-card>
            </div>

            <div style="box-sizing: border-box;" class="flex-1 pos-r">
                <div class="pos-a w-h-100" style="box-sizing: border-box;">
                    <el-card class="box-card w-h-100" shadow="never" style="margin-top: 16px;">
                        <div style="" class="w-h-100 ver-flex">
                            <div class="flex-1 pos-r">
                                <div class="pos-a w-h-100">

                                    <el-table :data="list" class="w-h-100" style="width: 100%" border v-loading="loading" element-loading-background="rgba(0, 0, 0, 0.5)">
                                        
                                        <el-table-column type="index" :label="$t('3eKEs1bExAXarYpdJemp')" width="55" align="center" :index="indexMethod" />
                                
                                        <el-table-column min-width="160" :show-overflow-tooltip="true" :label="$t('kJu7Trhi2W73OAVloSf')" align="center">
                                            <!--  -->
                                            <el-table-column min-width="160" align="center">
                                                <template #header>
                                                    <el-input :show-overflow-tooltip="true" type="text" :placeholder="$t('kJu7Trhi2W73OAVloSf')" v-model="searchVar.v_ProjectName" />
                                                </template>
                                                <template #default="scoped">
                                                    <span v-if="scoped.row.v_ProjectName">{{ scoped.row.v_ProjectName }}</span>
                                                    <span v-else>-</span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>
                                
                                        <el-table-column min-width="160" :show-overflow-tooltip="true" :label="$t('oQmKga3tHw8a3L3sgt9Xn')" align="center">
                                            <el-table-column :show-overflow-tooltip="true" min-width="160" align="center">
                                                <template #header>
                                                    <el-input type="text" :placeholder="$t('oQmKga3tHw8a3L3sgt9Xn')" v-model="searchVar.v_WorkExplain" />
                                                </template>
                                                <template #default="scope">
                                                    <span>{{ scope.row.hazardDetail && scope.row.hazardDetail[0] && scope.row.hazardDetail[0].v_WorkExplain || '-' }}</span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>
                                        
                                        <el-table-column min-width="160" :show-overflow-tooltip="true" :label="$t('znlr2HhiXheU4cdB8JdS4')"  align="center">
                                            <el-table-column :show-overflow-tooltip="true" min-width="160" align="center">
                                                <template #header>
                                                    <el-input type="text" :placeholder="$t('znlr2HhiXheU4cdB8JdS4')" v-model="searchVar.v_ApplyContent" />
                                                </template>
                                                <template #default="scoped">
                                                    <span v-if="scoped.row.v_ApplyContent">{{ scoped.row.v_ApplyContent }}</span>
                                                    <span v-else>-</span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>
                                        
                                        <el-table-column width="260" :formatter="formatDate" :show-overflow-tooltip="true" :label="$t('0EDVq0EaoQowa5yp4H0')" align="center">
                                            <el-table-column width="260" align="center">
                                                <template #header>
                                                    <el-date-picker
                                                        class="set-t"
                                                        v-model="searchVar.d_JobDate"
                                                        type="datetime"
                                                        value-format="YYYY-MM-DD HH:mm:ss"
                                                        :placeholder="$t('xYKtSx361Hm1x9r3giOx')"
                                                        popper-class="el-date-p"
                                                    >
                                                    </el-date-picker>
                                                </template>
                                                <template #default="scope">
                                                    <span v-if="scope.row.d_JobDate">{{ scope.row.d_JobDate }}</span>
                                                    <span v-else>-</span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>
                                        
                                        <el-table-column min-width="160" :show-overflow-tooltip="true" :label="$t('xuuQbgKgXbSnhNsF78bC')" align="center">
                                            <!--  -->
                                            <el-table-column :show-overflow-tooltip="true" min-width="160" align="center">
                                                <template #header>
                                                    <el-input type="text" :placeholder="$t('xuuQbgKgXbSnhNsF78bC')" v-model="searchVar.v_JobAddress" />
                                                </template>
                                                <template #default="scoped">
                                                    <span v-if="scoped.row.v_JobAddress">{{ scoped.row.v_JobAddress }}</span>
                                                    <span v-else>-</span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>
                                        
                                        <el-table-column min-width="160" :formatter="pushType" :show-overflow-tooltip="true" :label="$t('9k1l8ZfhXdrs9DDwIHlt')" align="center">
                                            <!--  -->
                                            <el-table-column :show-overflow-tooltip="true" min-width="160" align="center">
                                                <template #header>
                                                    <el-input type="text" :placeholder="$t('9k1l8ZfhXdrs9DDwIHlt')" v-model="searchVar.n_Type" />
                                                </template>
                                                <template #default="scoped">
                                                    <span v-if="scoped.row.n_Type">{{ scoped.row.n_Type }}</span>
                                                    <span v-else>-</span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>
                                        
                                        <!-- <el-table-column min-width="140" :show-overflow-tooltip="true" :formatter="auditStatus" prop="n_AuditState" :label="$t('uk_220Omr0p3DgKxFxwB4')" align="center" /> -->
                                        
                                        <el-table-column width="260" :formatter="formatDate" :show-overflow-tooltip="true" :label="$t('xun-jian-shi-jian')" align="center">
                                            <el-table-column :show-overflow-tooltip="true" width="260" align="center">
                                                <template #header>
                                                    <el-date-picker
                                                        class="set-t"
                                                        v-model="searchVar.d_AuditTime"
                                                        type="datetime"
                                                        value-format="YYYY-MM-DD HH:mm:ss"
                                                        :placeholder="$t('xYKtSx361Hm1x9r3giOx')"
                                                        popper-class="el-date-p"
                                                    >
                                                    </el-date-picker>
                                                </template>
                                                <template #default="scope">
                                                    <span v-if="scope.row.d_AuditTime">{{ scope.row.d_AuditTime }}</span>
                                                    <span v-else>-</span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>
                                        
                                        <el-table-column min-width="160" :show-overflow-tooltip="true" :label="$t('a_4BebW8b0g3aixOGa4Hj')" align="center">
                                            <el-table-column :show-overflow-tooltip="true" min-width="160" align="center">
                                                <template #header>
                                                    <el-input type="text" :placeholder="$t('a_4BebW8b0g3aixOGa4Hj')" v-model="searchVar.v_TeamName" />
                                                </template>
                                                <template #default="scoped">
                                                    <span v-if="scoped.row.v_TeamName">{{ scoped.row.v_TeamName }}</span>
                                                    <span v-else>-</span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>
                                        
                                        <el-table-column min-width="160" :show-overflow-tooltip="true" :label="$t('tPiWuSFanLeOKbJWvfz')" align="center">
                                            <el-table-column :show-overflow-tooltip="true" min-width="160" align="center">
                                                <template #header>
                                                    <el-input type="text" :placeholder="$t('tPiWuSFanLeOKbJWvfz')" v-model="searchVar.v_ApplyEmpName" />
                                                </template>
                                                <template #default="scoped">
                                                    <span v-if="scoped.row.v_ApplyEmpName">{{ scoped.row.v_ApplyEmpName }}</span>
                                                    <span v-else>-</span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>
                                        
                                        <el-table-column min-width="160" :show-overflow-tooltip="true" :label="$t('xun-jian-ren')" align="center">
                                            <el-table-column :show-overflow-tooltip="true" min-width="160" align="center">
                                                <template #header>
                                                    <el-input type="text" :placeholder="$t('xun-jian-ren')" v-model="searchVar.v_AuditEmpName" />
                                                </template>
                                                <template #default="scoped">
                                                    <span v-if="scoped.row.v_AuditEmpName">{{ scoped.row.v_AuditEmpName }}</span>
                                                    <span v-else>-</span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>
                                        
                                        <el-table-column min-width="160" :show-overflow-tooltip="true" :label="$t('z_6MaI6MYIAjEp9UeAfF')" align="center">
                                            <el-table-column :show-overflow-tooltip="true" min-width="160" align="center">
                                                <template #header>
                                                    <el-input type="text" :placeholder="$t('z_6MaI6MYIAjEp9UeAfF')" v-model="searchVar.v_CheckChangeEmpName" />
                                                </template>
                                                <template #default="scoped">
                                                    <span v-if="scoped.row.v_CheckChangeEmpName">{{ scoped.row.v_CheckChangeEmpName }}</span>
                                                    <span v-else>-</span>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>
                                        
                                        <el-table-column min-width="160" :show-overflow-tooltip="true" prop="n_isValid" :label="$t('rgcgOzqZdO2BeC4ZlZlTu')" align="center">
                                            <el-table-column :show-overflow-tooltip="true" min-width="160" align="center">
                                                <template #header>
                                                    <el-select 
                                                        v-model="transferVal" 
                                                        filterable 
                                                        class="m-2" 
                                                        :placeholder="$t('rgcgOzqZdO2BeC4ZlZlTu')" 
                                                        @change="acquireChange"
                                                        value-key="id"
                                                    >
                                                        <el-option
                                                            v-for="item in responsiblePle"
                                                            :key="item.value"
                                                            :label="item.label"
                                                            :value="item.value"
                                                        />
                                                    </el-select>
                                                </template>
                                                <template #default="scope">
                                                    <span v-if="scope.row.n_isValid === 1" style="color: #07AAF9;">{{ $t('tqK3NuaPwyfNtmCtUjfMc') }}</span>
                                                    <span v-if="scope.row.n_isValid === 2" style="color: #FF5F33;">{{ $t('q4t2O0Ze9Xzq62dJGwSJk') }}</span>
                                                </template>
                                            </el-table-column>
                                            
                                        </el-table-column>
                                        
                                        <el-table-column min-width="140" :show-overflow-tooltip="true" :label="$t('yAvTtpz0zMd6C5i3TqYvd')" align="center">
                                            <template #default="scope">
                                                <span style="cursor: pointer;" @click="fileClick(scope.row.v_FilePath , 1)" v-if="scope.row.v_FilePath && scope.row.v_FilePath.length !== 0">{{ $t('2KyEk7Ir2Lz3bN9ByjSaE') }}</span>
                                                <span v-else>{{ $t('tzv7Fao_8LvfFbddIkvDu') }}</span>
                                            </template>
                                        </el-table-column>
                                        
                                        <el-table-column min-width="140" :show-overflow-tooltip="true" :label="$t('h1NiJFxdxXsO9UmJbeMf')" align="center">
                                            <template #default="scope">
                                                <span style="cursor: pointer;" @click="fileClick(scope.row.v_ChangeFilePath , 2)" v-if="scope.row.v_ChangeFilePath && scope.row.v_ChangeFilePath.length !== 0">{{ $t('2KyEk7Ir2Lz3bN9ByjSaE') }}</span>
                                                <span v-else>{{ $t('tzv7Fao_8LvfFbddIkvDu') }}</span>
                                            </template>
                                        </el-table-column>
                                        
                                        <el-table-column min-width="160" :show-overflow-tooltip="true" prop="createdTime" :label="$t('xxAj6fsjvIsQrMdlNpolv')" align="center" />
                                        
                                        <el-table-column min-width="140" :show-overflow-tooltip="true" prop="createdUserName" :label="$t('v7AhfaNeGaFoPfZzgpFk')" align="center" />
                                        
                                        <el-table-column min-width="140" :show-overflow-tooltip="true" :label="$t('9RLaVEiJf1Z1Qv15o6Kll')" align="center">
                                            <template #default="scoped">
                                                <span v-if="scoped.row.v_Remake">{{ scoped.row.v_Remake }}</span>
                                                <span v-else>-</span>
                                            </template>
                                        </el-table-column>
                                         
                                        <el-table-column min-width="160" :label="$t('liBmO8wb58NMw5HLu9Nf')" align="center" fixed="right">
                                            <template #default="scope">
                                                <el-button v-if="$hasPer('riskHuizong:detail')" @click="nodeClick(scope.row)" class="icon-e" icon="ele-View" size="small" text type="primary"> {{ $t('ucC9qxHvkvdh9OGEo1pn') }} </el-button>
                                            </template>
                                        </el-table-column>

                                    </el-table>
                                </div>
                            </div>
                            <div style="height: 30px;margin-top: 20px;" class="hr-flex-start">
								<el-pagination
									v-model:currentPage="pageNo"
									v-model:page-size="pageSize"
									:total="totalRows"
									:page-sizes="[10, 20, 50, 100]"
									small
									background
									@size-change="handleSizeChange"
									@current-change="handleCurrentChange"
									layout="total, sizes, prev, pager, next, jumper"
									class="w-h-100"
								/>
							</div>
                        </div>
                    </el-card>
                </div>
            </div>
        </div>
        <huizong-detail
            :repairInfo="repairInfo"
            :isUseDialog="isUseDialog"
            @cancelDetailClick="cancelDetailClick"
        />
        <VModel
            :fileInfo="fileInfo"
            :isModelDialog="isModelDialog"
            @cancelModelClick="cancelModelClick"
        />
    </div>
</template>
<script lang="ts">
import { defineComponent, ref, onMounted , reactive , toRaw } from 'vue';
import getTableData from '/@/utils/getTableData';
import { RiskSummaryPage } from '/@/api/sms/sms';
import HuizongDetail from './component/huizong-detail.vue';
import VModel from '../components/v-model.vue';
import useCurrentInstance from '/@/utils/hook/useCurrentInstance';
export default defineComponent( {
    name: 'risk-huizong',
    components: { HuizongDetail , VModel },
    setup(props){
        const { proxy } = useCurrentInstance();
        const $t = proxy.$t;
        
        const isUseDialog = ref() // 新增/编辑弹出框隐藏/显示
        const repairInfo = ref() // 传递子组件数据
        const pathData = ref(import.meta.env.VITE_API_URL + '/') // 获取地址

        const isModelDialog = ref(false);
        const cancelModelClick = () => {isModelDialog.value = false};
        const fileInfo = ref('');

        /*** 查看文件 */
        const fileClick = (val: any , num: number) => {
            isModelDialog.value = true;
            let setObj: any = {};
            if(num === 1) setObj.titleInfo = $t('yAvTtpz0zMd6C5i3TqYvd');
            else setObj.titleInfo = $t('h1NiJFxdxXsO9UmJbeMf');
            setObj.rectifyListArr = val;
            fileInfo.value = JSON.stringify(setObj);
        }

        const searchVar = reactive({
            v_ProjectName: '',
            v_WorkExplain: '',
            v_ApplyContent: '',
            d_JobDate: '',
            v_JobAddress: '',
            n_Type: '',
            d_AuditTime: '',
            v_TeamName: '',
            v_ApplyEmpName: '',
            v_AuditEmpName: '',
            v_CheckChangeEmpName: '',
        });
        
        // 搜索类
        const searchVal = ref('1')
        const transferVal = ref() // 需要查询的值
        let searchObj:any = reactive({})
        let searchName = '1'
        /*** resetFun */
        const resetFun = () => {
            let newObj = Object.keys(searchObj)
            if(newObj.length !== 0){
                newObj.map((i:any) => {
                    searchObj[i] = ''
                })
            }
        }
        /*** 搜索类型选择事件 searchChange */
        const searchChange = (val:any) => {
            searchName = val
            transferVal.value = ''
        }
        /*** acquireChange 搜索下拉框选择的数据 ---- 传给接口数据 */
        const acquireChange = (val:any) => {
            console.log(val)
        }
        /*** searchClick 查询按钮 */
        const searchClick = () => {
            resetFun()
            if(searchName === '1'){ searchObj.searchValue = transferVal.value }
            if(searchName === '2'){ searchObj.n_isValid = transferVal.value }
            if(searchName === '3'){ 
                searchObj.startTime = toRaw(transferVal.value)[0] 
                searchObj.endTime = toRaw(transferVal.value)[1]
            } 
        }
        /*** resetClick 重置按钮 */
        const resetClick = () => {
            resetFun()
            transferVal.value = ''
            searchVal.value = '1'
        }
        // 搜索类

        /*** 截取日期格式方法 */
        const formatDate = (row:any, column:any) => {
          // 获取单元格数据
          let data = row[column.property]
          if(data == $t('utiIUzqSzcKy0QiDc49n')){
            return '-'
          }else{
            return data
          }
        }

        /*** 推送类型数据处理 */
        const pushType = (row:any, column:any) => {
            let data = row[column.property]
            if(data <= 1){
                return $t('7dvrp8KNteJ2KsyX53N')
            }else if(data === 2){
                return $t('0GdEpZhBB3RGlirtCm1U')
            }else if(data === 3){
                return $t('w3sd0wQwiYthGeopJcU4t')
            }else if(data === 4){
                return $t('eec8W28NIj_1hBweAkWs')
            }else if(data === 5){
                return $t('tuRoDlk7koL463Gf9SbzY')
            }
        }

        /*** auditStatus 审批状态数据处理 */
        const auditStatus = (row:any, column:any) => {
            let data = row[column.property]
            // 这里有点问题之前的逻辑是 <= 1
            if(data < 0){
                // 不通过
                return $t('w4VhwoPcGmZvsLAw9Ejgt')
            }else if(data === 0){
                return $t('gf0Sq2nS1hOty874oBt4g')
            }else if(data === 1){
                return $t('1uO8o9kmpBShOnoFlN')
            }else if(data === 2){
                return $t('1Eky213Jts1mf6p7goA9L')
            }else if(data === 3){
                return $t('o8f7fCjMywm3YjIudQiC')
            }else if(data === 4){
                return $t('gf1hWfVmK0UkFtSUxMxtg')
            }
        }

        /*** nodeClick 新增/编辑点击事件 */
        const nodeClick = (val:string | object) => {
            val !== '' ? repairInfo.value = JSON.stringify(toRaw(val)) : repairInfo.value = ''
            isUseDialog.value = true
        }

        /*** cancelDetailClick 详情关闭事件 */
        const cancelDetailClick = () => {
            isUseDialog.value = false
        }

        /*** deleteHandle 删除数据事件 */
        const deleteHandle = async (val: String | Number , updateFun: Function) => {
            console.log('删除事件')
            return
            let param = {id : val}
            try {
                // let res = await sysPosDelete(param)
                let res:any = {}
                if(res.success){
                    updateFun()
                }
            } catch (err) { return }
        }

        /*** cancelUseClick 取消事件 */
        const cancelUseClick = () => {
            isUseDialog.value = false
        }

        /*** controlUseClick 提交事件 */
        const controlUseClick = () => {
            isUseDialog.value = false
        }

        return {
            ...getTableData(RiskSummaryPage,{},searchObj),
            isUseDialog,
            cancelUseClick,
            controlUseClick,
            nodeClick,
            repairInfo,
            deleteHandle,

            // 搜索类
            searchVal,
            transferVal,
            resetClick,
            searchClick,
            searchChange,
            acquireChange,
            searchOptions: [{
                value: '1',
                label: $t('3dBd6Gp5MqNm4A5dvcqJ4')
            }, {
                value: '2',
                label: $t('4qSllUxIkPaA8Rqf3Jg8y')
            }, {
                value: '3',
                label: $t('bxOzlOcGrW1Oanu81ddgi')
            }], // 搜索方式
            responsiblePle: [
                { label: $t('iPfonvtxVLm7knSyCsLBo') , value: 1 },
                { label: $t('tzm8JwYsKnqKoNhheJlJx') , value: 2 },
            ], // 是否启用
            // 搜索类

            pathData,
            cancelDetailClick,
            formatDate,
            pushType,
            auditStatus,
            searchVar,
            
            isModelDialog,
            cancelModelClick,
            fileInfo,
            fileClick,
        }
    },
} )
</script>
<style lang="scss"> @import '../style/public.scss'; </style>
<style scoped lang="scss">
    :deep(.el-link__inner){
        color: #0052D9;
    }
    #risk-huizong {
        .box-f{
            :deep(.el-form-item__label){
                padding: 0;
            }
        }
        :deep(.el-card__body) {
            height: 100%;
        }
        :deep(.el-card){
            border: none !important;
        }
        ul {

            list-style: none;

            li {
                cursor: pointer;

                &:hover {
                    color: red;
                }
            }
        }
        .icon-e{
            :deep(.el-icon){
                margin-right: 0px!important;
            }
        }
    }
</style>